package com.bjim.client;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import cn.dreampie.client.Client;
import cn.dreampie.client.ClientRequest;
import cn.dreampie.client.ClientResult;

public class ClientTest {
	public static void main(String[] args) {
			Client client=new Client("http://7.207.155.28:9019/structService/findCompanyList");
			ClientRequest request=new ClientRequest();
			request.setContentType("application/json");
			request.setJsonParam("{}");
			 ClientResult getResult = client.build(request).post();
			 String result=getResult.getResult();
			 JSONObject jo=JSONObject.parseObject(result);
			 JSONArray rows=jo.getJSONArray("rows");
			 for(int i=0;i<rows.size();i++){
				 JSONObject company= rows.getJSONObject(i);
				 String companyId=company.getString("id");
				 String companyCode=company.getString("companyCode");
				 String companyNameZh=company.getString("companyNameZh");
				 System.out.printf("companyId=%s,companyCode=%s,companyNameZh=%s",companyId,companyCode,companyNameZh);
				 System.out.println();
				 JSONArray departments=company.getJSONArray("departments");
				 if(departments==null)
					 continue;
				 for(int j=0;j<departments.size();j++){
					 JSONObject department= departments.getJSONObject(j);
					 String depid= department.getString("id");
					 String depcompanyId= department.getString("companyId");
					 String dpartmentCode=department.getString("dpartmentCode");
					 String departmentNameZh= department.getString("departmentNameZh");
					 System.out.printf("depid=%s,dpartmentCode=%s,departmentNameZh=%s",depid,dpartmentCode,departmentNameZh);
					 System.out.println();
					 JSONArray users=department.getJSONArray("users");
					 if(users==null)
						 continue;
					 for(int k=0;k<users.size();k++){
						 JSONObject user= users.getJSONObject(k);
						String userid= user.getString("id");
						String userMemo= user.getString("userMemo");
						//String userid= user.getString("id");
						 System.out.printf("userid=%s,userMemo=%s",userid,userMemo);
						 System.out.println();
					 }
				 }
			 }
			 
			 
	}
}
